package io.kiki.sba.registry.server.data_store.multi.cluster.exchanger;

import io.kiki.sba.registry.api.ChannelHandler;
import io.kiki.sba.registry.api.exchange.DataExchanger;
import io.kiki.sba.registry.server.data_store.bootstrap.MultiClusterDataServerConfig;
import io.kiki.sba.registry.server.shared.remoting.ClientSideExchanger;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.Collection;


public class RemoteDataNodeExchanger extends ClientSideExchanger {

    @Autowired
    private MultiClusterDataServerConfig multiClusterDataServerConfig;

    @Resource(name = "remoteDataClientHandlers")
    private Collection<ChannelHandler> remoteDataClientHandlers;

    public RemoteDataNodeExchanger() {
        super(DataExchanger.REMOTE_DATA_SERVER_TYPE);
    }


    @Override
    public int getRpcTimeoutMillis() {
        return multiClusterDataServerConfig.getSyncRemoteSlotLeaderTimeoutMillis();
    }

    @Override
    public int getServerPort() {
        return multiClusterDataServerConfig.getSyncRemoteSlotLeaderPort();
    }

    @Override
    public int getConnNum() {
        return multiClusterDataServerConfig.getSyncRemoteSlotLeaderConnNum();
    }

    @Override
    protected Collection<ChannelHandler> getClientHandlers() {
        return remoteDataClientHandlers;
    }
}
